<!DOCTYPE html><html><head>
<title>doctools::tcl::parse - Documentation tools</title>
<style type="text/css"><!--
    HTML {
	background: 	#FFFFFF;
	color: 		black;
    }
    BODY {
	background: 	#FFFFFF;
	color:	 	black;
    }
    DIV.doctools {
	margin-left:	10%;
	margin-right:	10%;
    }
    DIV.doctools H1,DIV.doctools H2 {
	margin-left:	-5%;
    }
    H1, H2, H3, H4 {
	margin-top: 	1em;
	font-family:	sans-serif;
	font-size:	large;
	color:		#005A9C;
	background: 	transparent;
	text-align:		left;
    }
    H1.doctools_title {
	text-align: center;
    }
    UL,OL {
	margin-right: 0em;
	margin-top: 3pt;
	margin-bottom: 3pt;
    }
    UL LI {
	list-style: disc;
    }
    OL LI {
	list-style: decimal;
    }
    DT {
	padding-top: 	1ex;
    }
    UL.doctools_toc,UL.doctools_toc UL, UL.doctools_toc UL UL {
	font:		normal 12pt/14pt sans-serif;
	list-style:	none;
    }
    LI.doctools_section, LI.doctools_subsection {
	list-style: 	none;
	margin-left: 	0em;
	text-indent:	0em;
	padding: 	0em;
    }
    PRE {
	display: 	block;
	font-family:	monospace;
	white-space:	pre;
	margin:		0%;
	padding-top:	0.5ex;
	padding-bottom:	0.5ex;
	padding-left:	1ex;
	padding-right:	1ex;
	width:		100%;
    }
    PRE.doctools_example {
	color: 		black;
	background: 	#f5dcb3;
	border:		1px solid black;
    }
    UL.doctools_requirements LI, UL.doctools_syntax LI {
	list-style: 	none;
	margin-left: 	0em;
	text-indent:	0em;
	padding:	0em;
    }
    DIV.doctools_synopsis {
	color: 		black;
	background: 	#80ffff;
	border:		1px solid black;
	font-family:	serif;
	margin-top: 	1em;
	margin-bottom: 	1em;
    }
    UL.doctools_syntax {
	margin-top: 	1em;
	border-top:	1px solid black;
    }
    UL.doctools_requirements {
	margin-bottom: 	1em;
	border-bottom:	1px solid black;
    }
--></style>
</head>
<!-- Generated from file 'tcl_parse.man' by tcllib/doctools with format 'html'
   -->
<!-- Copyright &amp;copy; 2009 Andreas Kupries &amp;lt;andreas_kupries@users.sourceforge.net&amp;gt;
   -->
<!-- doctools::tcl::parse.n
   -->
<body><hr> [
   <a href="../../../../../../../../home">Tcllib Home</a>
&#124; <a href="../../../../toc.html">Main Table Of Contents</a>
&#124; <a href="../../../toc.html">Table Of Contents</a>
&#124; <a href="../../../../index.html">Keyword Index</a>
&#124; <a href="../../../../toc0.html">Categories</a>
&#124; <a href="../../../../toc1.html">Modules</a>
&#124; <a href="../../../../toc2.html">Applications</a>
 ] <hr>
<div class="doctools">
<h1 class="doctools_title">doctools::tcl::parse(n) 1 tcllib &quot;Documentation tools&quot;</h1>
<div id="name" class="doctools_section"><h2><a name="name">Name</a></h2>
<p>doctools::tcl::parse - Processing text in 'subst -novariables' format</p>
</div>
<div id="toc" class="doctools_section"><h2><a name="toc">Table Of Contents</a></h2>
<ul class="doctools_toc">
<li class="doctools_section"><a href="#toc">Table Of Contents</a></li>
<li class="doctools_section"><a href="#synopsis">Synopsis</a></li>
<li class="doctools_section"><a href="#section1">Description</a></li>
<li class="doctools_section"><a href="#section2">API</a></li>
<li class="doctools_section"><a href="#section3">Error format</a></li>
<li class="doctools_section"><a href="#section4">Tree Structure</a></li>
<li class="doctools_section"><a href="#section5">Bugs, Ideas, Feedback</a></li>
<li class="doctools_section"><a href="#keywords">Keywords</a></li>
<li class="doctools_section"><a href="#category">Category</a></li>
<li class="doctools_section"><a href="#copyright">Copyright</a></li>
</ul>
</div>
<div id="synopsis" class="doctools_section"><h2><a name="synopsis">Synopsis</a></h2>
<div class="doctools_synopsis">
<ul class="doctools_requirements">
<li>package require <b class="pkgname">Tcl 8.4</b></li>
<li>package require <b class="pkgname">snit</b></li>
<li>package require <b class="pkgname">fileutil</b></li>
<li>package require <b class="pkgname">logger</b></li>
<li>package require <b class="pkgname">struct::list</b></li>
<li>package require <b class="pkgname">struct::stack</b></li>
<li>package require <b class="pkgname">struct::set</b></li>
<li>package require <b class="pkgname">treeql</b></li>
<li>package require <b class="pkgname">doctools::tcl::parse</b></li>
</ul>
<ul class="doctools_syntax">
<li><a href="#1"><b class="cmd">::doctools::tcl::parse</b> <b class="method">text</b> <i class="arg">tree</i> <i class="arg">text</i> <span class="opt">?<i class="arg">root</i>?</span></a></li>
<li><a href="#2"><b class="cmd">::doctools::tcl::parse</b> <b class="method">file</b> <i class="arg">tree</i> <i class="arg">path</i> <span class="opt">?<i class="arg">root</i>?</span></a></li>
</ul>
</div>
</div>
<div id="section1" class="doctools_section"><h2><a name="section1">Description</a></h2>
<p>This package provides commands for parsing text with embedded Tcl
commands as accepted by the Tcl builtin command
<b class="cmd">subst -novariables</b>. The result of the parsing is an abstract
syntax tree.</p>
<p>This is an internal package of doctools, for use by the higher level
parsers processing the <i class="term"><a href="../../../../index.html#docidx">docidx</a></i>, <i class="term"><a href="../../../../index.html#doctoc">doctoc</a></i>, and <i class="term"><a href="../../../../index.html#doctools">doctools</a></i>
markup languages.</p>
</div>
<div id="section2" class="doctools_section"><h2><a name="section2">API</a></h2>
<dl class="doctools_definitions">
<dt><a name="1"><b class="cmd">::doctools::tcl::parse</b> <b class="method">text</b> <i class="arg">tree</i> <i class="arg">text</i> <span class="opt">?<i class="arg">root</i>?</span></a></dt>
<dd><p>The command takes the <i class="arg">text</i> and parses it under the assumption
that it contains a string acceptable to the Tcl builtin command
<b class="cmd">subst -novariables</b>. Errors are thrown otherwise during the
parsing. The format used for these errors in described in section
<span class="sectref"><a href="#section3">Error format</a></span>.</p>
<p>The command returns the empty string as it result. The actual result
of the parsing is entered into the tree structure <i class="arg">tree</i>, under
the node <i class="arg">root</i>.
If <i class="arg">root</i> is not specified the root of <i class="arg">tree</i> is used. The
<i class="arg">tree</i> has to exist and be the command of a tree object which
supports the same methods as trees created by the package
<b class="package"><a href="../struct/struct_tree.html">struct::tree</a></b>.</p>
<p>In case of errors <i class="arg">tree</i> will be left in an undefined state.</p></dd>
<dt><a name="2"><b class="cmd">::doctools::tcl::parse</b> <b class="method">file</b> <i class="arg">tree</i> <i class="arg">path</i> <span class="opt">?<i class="arg">root</i>?</span></a></dt>
<dd><p>The same as <b class="method">text</b>, except that the text to parse is read from
the file specified by <i class="arg">path</i>.</p></dd>
</dl>
</div>
<div id="section3" class="doctools_section"><h2><a name="section3">Error format</a></h2>
<p>When the parser encounters a problem in the input
it will throw an error using the format described
here.</p>
<ol class="doctools_enumerated">
<li><p>The message will contain the reason for the problem (unexpected
character or end of input in input), the character in question, if
any, and the line and column the problem was found at, in a human
readable form. This part is not documented further as its format may
change as we see fit. It is intended for human consumption, not
machine.</p></li>
<li><p>The error code however will contain a machine-readable representation
of the problem, in the form of a 5-element list containing, in the
order listed below</p>
<ol class="doctools_enumerated">
<li><p>the constant string <b class="const">doctools::tcl::parse</b></p></li>
<li><p>the cause of the problem, one of</p>
<dl class="doctools_definitions">
<dt><b class="const">char</b></dt>
<dd><p>Unexpected character in input</p></dd>
<dt><b class="const">eof</b></dt>
<dd><p>Unexpected end of the input</p></dd>
</dl>
</li>
<li><p>The location of the problem as offset from the beginning of the input,
counted in characters. Note: Line markers count as one character.</p></li>
<li><p>The line the problem was found on (counted from 1 (one)),</p></li>
<li><p>The column the problem was found at (counted from 0 (zero))</p></li>
</ol>
</li>
</ol>
</div>
<div id="section4" class="doctools_section"><h2><a name="section4">Tree Structure</a></h2>
<p>After successfully parsing a string the generated tree will have the
following structure:</p>
<ol class="doctools_enumerated">
<li><p>In the following items the word 'root' refers to the node which was
specified as the root of the tree when invoking either <b class="method">text</b>
or <b class="method">file</b>. This may be the actual root of the tree.</p></li>
<li><p>All the following items further ignore the possibility of pre-existing
attributes in the pre-existing nodes. If attributes exists with the
same names as the attributes used by the parser the pre-existing
values are written over. Attributes with names not clashing with the
parser's attributes are not touched.</p></li>
<li><p>The root node has no attributes.</p></li>
<li><p>All other nodes have the attributes</p>
<dl class="doctools_definitions">
<dt>type</dt>
<dd><p>The value is a string from the set { Command , Text , Word }</p></dd>
<dt>range</dt>
<dd><p>The value is either empty or a 2-element list containing integer
numbers. The numbers are the offsets of the first and last character
in the input text, of the token described by the node,.</p></dd>
<dt>line</dt>
<dd><p>The value is an integer, it describes the line in the input the token
described by the node ends on. Lines are counted from 1 (<b class="const">one</b>).</p></dd>
<dt>col</dt>
<dd><p>The value is an integer, it describes the column in the line in the
input the token described by the node ends on. Columns are counted
from 0 (<b class="const">zero</b>).</p></dd>
</dl>
</li>
<li><p>The children of the root, if any, are of type Command and Text, in
semi-alternation. This means: After a Text node a Command node has to
follow, and anything can follow a Command node, a Text or other
Command node.</p></li>
<li><p>The children of a Command node, if any, are of type Command, and Text,
and Word, they describe the arguments of the command.</p></li>
<li><p>The children of a Word node, if any, are of type Command, Text, in
semi-alternation. This means: After a Text node a Command node has to
follow, and anything can follow a Command node, a Text or other
Command node.</p></li>
<li><p>A Word node without children represents the empty string.</p></li>
<li><p>All Text nodes are leaves of the tree.</p></li>
<li><p>All leaves of the tree are either Text or Command nodes.
Word nodes cannot be leaves.</p></li>
</ol>
</div>
<div id="section5" class="doctools_section"><h2><a name="section5">Bugs, Ideas, Feedback</a></h2>
<p>This document, and the package it describes, will undoubtedly contain
bugs and other problems.
Please report such in the category <em>doctools</em> of the
<a href="http://core.tcl.tk/tcllib/reportlist">Tcllib Trackers</a>.
Please also report any ideas for enhancements you may have for either
package and/or documentation.</p>
<p>When proposing code changes, please provide <em>unified diffs</em>,
i.e the output of <b class="const">diff -u</b>.</p>
<p>Note further that <em>attachments</em> are strongly preferred over
inlined patches. Attachments can be made by going to the <b class="const">Edit</b>
form of the ticket immediately after its creation, and then using the
left-most button in the secondary navigation bar.</p>
</div>
<div id="keywords" class="doctools_section"><h2><a name="keywords">Keywords</a></h2>
<p><a href="../../../../index.html#tcl_syntax">Tcl syntax</a>, <a href="../../../../index.html#command">command</a>, <a href="../../../../index.html#doctools">doctools</a>, <a href="../../../../index.html#parser">parser</a>, <a href="../../../../index.html#subst">subst</a>, <a href="../../../../index.html#word">word</a></p>
</div>
<div id="category" class="doctools_section"><h2><a name="category">Category</a></h2>
<p>Documentation tools</p>
</div>
<div id="copyright" class="doctools_section"><h2><a name="copyright">Copyright</a></h2>
<p>Copyright &copy; 2009 Andreas Kupries &lt;andreas_kupries@users.sourceforge.net&gt;</p>
</div>
</div></body></html>
